package com.example.questionnaires.controller;

import com.example.questionnaires.common.Result;
import com.example.questionnaires.dto.AnnouncementCommentDTO;
import com.example.questionnaires.entity.User;
import com.example.questionnaires.service.AnnouncementCommentService;
import com.example.questionnaires.service.UserService;
import com.example.questionnaires.utils.UserContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/announcement")
public class AnnouncementCommentController {

    @Resource
    private AnnouncementCommentService commentService;

    @GetMapping("/{announcementId}/comments")
    public Result<List<AnnouncementCommentDTO>> getComments(@PathVariable Long announcementId) {
        return Result.success(commentService.getCommentsByAnnouncementId(announcementId));
    }

    @PostMapping("/{announcementId}/comments")
    public Result<Void> addComment(
        @PathVariable Long announcementId,
        @RequestParam String content
    ) {
        commentService.addComment(announcementId, content);
        return Result.success();
    }

    @DeleteMapping("/{announcementId}/comments/{commentId}")
    public Result<Void> deleteComment(
        @PathVariable Long commentId
    ) {
        commentService.deleteComment(commentId);
        return Result.success();
    }
}
